import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

import javax.swing.JDialog;

public class changeIP extends JDialog implements ActionListener{
	private JPanel jpnIP,jpnNom,jpnMasque,jpnButton,jpnMaster;
	private JLabel jlbIP,jlbNom,jlbMasque;
	private JTextField jtfIP,jtfNom,jtfMasque;
	private JButton jbtOk,jbtAnnuler;
	String IP;
	
public changeIP(String IPs)
	{
		IP=IPs;
		jpnIP=new JPanel(new FlowLayout(FlowLayout.CENTER));
		jpnNom=new JPanel(new FlowLayout(FlowLayout.CENTER));
		jpnMasque=new JPanel(new FlowLayout(FlowLayout.CENTER));
		jpnButton=new JPanel(new FlowLayout(FlowLayout.CENTER));
		jpnMaster=new JPanel(new GridLayout(4,1));
		
		jlbIP=new JLabel("Nouveau Adresse IP");
		jlbMasque=new JLabel("Masque de l'Adresse");
		jlbNom=new JLabel("Fichier de Syntaxe     ");
		
		
		jtfIP=new JTextField(15);
		jtfMasque=new JTextField(15);
		jtfNom=new JTextField(15);
		
		jbtOk=new JButton("OK");
		jbtAnnuler=new JButton("Annuler");
		
		jpnIP.add(jlbIP);
		jpnIP.add(jtfIP);
		jpnNom.add(jlbNom);
		jpnNom.add(jtfNom);
		jpnMasque.add(jlbMasque);
		jpnMasque.add(jtfMasque);
		
		jpnButton.add(jbtOk);
		jpnButton.add(jbtAnnuler);
		
		jpnMaster.add(jpnIP);
		jpnMaster.add(jpnMasque);
		jpnMaster.add(jpnNom);
		jpnMaster.add(jpnButton);
		
		getContentPane().add(jpnMaster,BorderLayout.CENTER);
		
		setTitle("Change IP");
		setSize(400,300);
		setResizable(true);
		setLocationRelativeTo(this.getParent());
		jbtOk.addActionListener(this);
		jbtAnnuler.addActionListener(this);
		
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e)
			{
				dispose();
			}
		}
		);	
		
	}
	
public void actionPerformed(ActionEvent e) {
		
		if (e.getSource()==jbtAnnuler){
			this.dispose();		
		}	
		else if (e.getSource()==jbtOk){
			String fichier = jtfNom.getText();
			String ip=jtfIP.getText();
			syntaxParser sP=new syntaxParser(fichier);
			String cmd=sP.getCmdIP();	
			System.out.println("Commande : "+cmd);
			cmdTelnet ch= new cmdTelnet(IP,cmd+" "+ip+(char)13+"exit"+(char)13+"exit"+(char)13+"exit");
		}	
	}
}
